/**
 * File Name:		DateAdapter.java
 * Package Name:	com.sable.engine.jaxb
 * Project Name:	SABLE
 * Create Date:		Apr 15, 2011 2:57:15 PM
 * Create By:		shangxj
 */
package com.googlecode.jtoy.jee.jaxb.adapter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.annotation.adapters.XmlAdapter;

/**
 * 本类用于解组和编组时的时间日期转化
 * 
 * @author shangxj
 * @date Apr 15, 2011 2:57:15 PM
 */
public class DateAdapter extends XmlAdapter<String, Date> {

	private DateFormat format = new SimpleDateFormat("yyyyMMddHHssmm");

	/**
	 * 解组时将时间串转化成日期
	 * 
	 * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
	 */
	@Override
	public Date unmarshal(String value) throws Exception {
		return format.parse(value);
	}

	/**
	 * 编组时将日期转化成时间串
	 * 
	 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
	 */
	@Override
	public String marshal(Date date) throws Exception {
		return format.format(date);
	}

}
